{
  LW Shader -- LightWave Surface Shaders

  Shaders set the color and other appearance attributes of each visible spot on a surface.

  Based on lwshader.h which is:
  Copyright 1999, NewTek, Inc.
}

{
  Copyright 2012, Jameel Halabi

  This unit is part of the BlaiseWave wrapper,
  which is licensed under the BSD 2-Clause license (see licenses/license.txt).
}
unit LW_Shader;

{$mode objfpc}{$H+}

interface

uses
  LW_Types      ,
  LW_Meshes     ,
  LW_Handler    ,
  LW_Render     ,
  LW_Instancing ;

const
  LWSHADER_HCLASS  = 'ShaderHandler'   ;
  LWSHADER_ICLASS  = 'ShaderInterface' ;
  LWSHADER_GCLASS  = 'ShaderGizmo'     ;
  LWSHADER_VERSION = 7                 ;

  LWSHF_NORMAL         = 1 shl 0  ;
  LWSHF_COLOR          = 1 shl 1  ;
  LWSHF_LUMINOUS       = 1 shl 2  ;
  LWSHF_DIFFUSE        = 1 shl 3  ;
  LWSHF_SPECULAR       = 1 shl 4  ;
  LWSHF_MIRROR         = 1 shl 5  ;
  LWSHF_TRANSP         = 1 shl 6  ;
  LWSHF_ETA            = 1 shl 7  ;
  LWSHF_ROUGH          = 1 shl 8  ;
  LWSHF_TRANSLUCENT    = 1 shl 9  ;
  LWSHF_RAYTRACE       = 1 shl 10 ;
  LWSHF_DIFFUSE_SHADE  = 1 shl 11 ;
  LWSHF_SPECULAR_SHADE = 1 shl 12 ;
  LWSHF_REFRACT_SHADE  = 1 shl 13 ;
  LWSHF_REFLECT_SHADE  = 1 shl 14 ;
  LWSHF_MAX_CHANNELS   = 15       ;

type
  PLWShaderAccess = ^TLWShaderAccess ;
  TLWShaderAccess = record
    Sx			   ,
    Sy			   : Integer                       ;
    OPos   		   ,
    WPos   	           ,
    GNorm   		   : array [0..2] of Double        ;
    SpotSize		   : Double                        ;
    RaySource   	   : array [0..2] of Double        ;
    RayLength		   : Double   	                   ;
    Cosine		   : Double   	                   ;
    OXfrm                  ,
    WXfrm   	           : array [0..8] of Double        ;
    ObjID		   : PLWItem  		           ;
    PolNum		   : Integer  		           ;

    WNorm                  ,
    Color                  : array [0..2] of Double        ;
    Luminous               : Double                        ;
    Diffuse                : Double                        ;
    Specular               : Double                        ;
    Mirror                 : Double                        ;
    Transparency           : Double                        ;
    Eta                    : Double                        ;
    Roughness              : Double                        ;

    Illuminate             : TLWIlluminateFunc             ;
    RayTrace               : TLWRayTraceFunc               ;
    RayCast                : TLWRayCastFunc                ;
    RayShade               : TLWRayShadeFunc               ;

    Flags                  : Integer                       ;
    Bounces                : Integer                       ;
    SourceID               : PLWItem                       ;
    WNorm0                 : array [0..2] of Double        ;
    BumpHeight             : Double                        ;
    Translucency           : Double                        ;
    ColorHL                : Double                        ;
    ColorFL                : Double                        ;
    AddTransparency        : Double                        ;
    DifSharpness           : Double                        ;

    VertsID                : array [0..3] of PLWPnt        ; // surrounding vertex IDs
    Weights                : array [0..3] of Single        ; // vertex weigths
    VertsWPos              : array [0..3, 0..2] of Single  ; // vertex world positions
    PolygonID              : PLWPol                        ; // polygon ID

    ReplacementPercentage  : Double                        ;
    ReplacementColor       : array [0..2] of Double        ;
    ReflectionBlur         : Double                        ;
    RefractionBlur         : Double                        ;

    RayTraceMode           : TLWRayTraceModeFunc           ;
    IncomingEta            : Double                        ;
    ResourceContextIndex   : Integer                       ;
    Diffuse_shade          ,
    Specular_shade         ,
    Refract_shade          ,
    Reflect_shade          : array [0..2] of Double        ;

    IlluminateSample       : TLWIlluminateSampleFunc       ;
    RandomData             : PRandomFloatData              ;
    RandomFloat            : TLWRandomFloatFunc            ;

    IlluminateNormal       : TLWIlluminateNormalFunc       ;
    IlluminateSampleNormal : TLWIlluminateSampleNormalFunc ;

    Subsx, subsy           : Double                        ;
    BumpDropoff            : Double                        ;

    RayDir                 : TLWDVector                    ;

    RayTraceData           : TLWRayTraceDataFunc           ;
    RayTraceShade          : TLWRayTraceShadeFunc          ;
    Render                 : PLWRenderData                 ;

    GetVal                 : TLWBufferGetValFunc           ;
    SetVal                 : TLWBufferSetValFunc           ;

    InstanceID             : PLWItemInstance               ;

    SamplerState           : PLWSamplerState               ;
    GetSamplerRange        : TLWGetSamplerRangeFunc        ;
    GetSample2D            : TLWGetSample2DFunc            ;
    GetSample1D            : TLWGetSample1DFunc            ;
  end;

  PLWShaderHandler = ^TLWShaderHandler ;
  TLWShaderHandler = record
    Inst           : PLWInstanceFuncs;
    Item           : PLWItemFuncs    ;
    Rend           : PLWRenderFuncs  ;
    Evaluate       : procedure
                     (      Instance : PLWInstance       ;
                      const Access   : PLWShaderAccess   ) ;
    Flags          : function
                     (      Instance : PLWInstance       ) : UInt32;
  end;

implementation

end.

